package com.ruoyi.project.jiaqin.wanttobuycollect.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.jiaqin.wanttobuycollect.domain.WantToBuyCollect;
import com.ruoyi.project.jiaqin.wanttobuycollect.service.IWantToBuyCollectService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 求购收藏Controller
 * 
 * @author LCL
 * @date 2021-10-22
 */
@Controller
@RequestMapping("/jiaqin/wanttobuycollect")
public class WantToBuyCollectController extends BaseController
{
    private String prefix = "jiaqin/wanttobuycollect";

    @Autowired
    private IWantToBuyCollectService wantToBuyCollectService;

    @RequiresPermissions("jiaqin:wanttobuycollect:view")
    @GetMapping()
    public String wanttobuycollect()
    {
        return prefix + "/wanttobuycollect";
    }

    /**
     * 查询求购收藏列表
     */
    @RequiresPermissions("jiaqin:wanttobuycollect:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WantToBuyCollect wantToBuyCollect)
    {
        startPage();
        List<WantToBuyCollect> list = wantToBuyCollectService.selectWantToBuyCollectList(wantToBuyCollect);
        return getDataTable(list);
    }

    /**
     * 导出求购收藏列表
     */
    @RequiresPermissions("jiaqin:wanttobuycollect:export")
    @Log(title = "求购收藏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WantToBuyCollect wantToBuyCollect)
    {
        List<WantToBuyCollect> list = wantToBuyCollectService.selectWantToBuyCollectList(wantToBuyCollect);
        ExcelUtil<WantToBuyCollect> util = new ExcelUtil<WantToBuyCollect>(WantToBuyCollect.class);
        return util.exportExcel(list, "wanttobuycollect");
    }

    /**
     * 新增求购收藏
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存求购收藏
     */
    @RequiresPermissions("jiaqin:wanttobuycollect:add")
    @Log(title = "求购收藏", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WantToBuyCollect wantToBuyCollect)
    {
        return toAjax(wantToBuyCollectService.insertWantToBuyCollect(wantToBuyCollect));
    }

    /**
     * 修改求购收藏
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        WantToBuyCollect wantToBuyCollect = wantToBuyCollectService.selectWantToBuyCollectById(id);
        mmap.put("wantToBuyCollect", wantToBuyCollect);
        return prefix + "/edit";
    }

    /**
     * 修改保存求购收藏
     */
    @RequiresPermissions("jiaqin:wanttobuycollect:edit")
    @Log(title = "求购收藏", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WantToBuyCollect wantToBuyCollect)
    {
        return toAjax(wantToBuyCollectService.updateWantToBuyCollect(wantToBuyCollect));
    }

    /**
     * 删除求购收藏
     */
    @RequiresPermissions("jiaqin:wanttobuycollect:remove")
    @Log(title = "求购收藏", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wantToBuyCollectService.deleteWantToBuyCollectByIds(ids));
    }
}
